/*
 * @Author: your name
 * @Date: 2021-04-12 23:45:15
 * @LastEditTime: 2021-04-14 00:07:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \guessing_game\src\main.rs
 */
//从标准库中引入了输入/输出功能
use std::io;
use rand::Rng;
use std::cmp::Ordering;

fn main() {
    println!("guess the number!");

    let secret_number = rand::thread_rng().gen_range(1,101);

    println!("the secret number is :{}", secret_number);

    println!("please input you guess.");
    let mut foo = 5;  // mut 让变量可变
    // 创建了一个可变变量，当前它绑定到一个新的 String 空实例上。
    let mut guess = String::new();

    io::stdin().read_line(&mut guess)
        .expect("failed to read line");

    let guess:u32 = guess.trim().parse()
        .expect("please type a number!");
    println!("you guessed:{} foo is {}",guess,foo);

    match guess.cmp(&secret_number){
        Ordering::Less => println!("too small"),
        Ordering::Greater => println!("too big"),
        Ordering::Equal => println!("you win"),
    }
}
